package com.hobart.learning.lagou.edu.IPersistence.sqlSession;

import com.hobart.learning.lagou.edu.IPersistence.config.XMLConfigBuilder;
import com.hobart.learning.lagou.edu.IPersistence.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @author ：hobart
 * @date ：Created in 2020-11-10 14:57
 * @description：构建 SqlSession 工厂
 * @modified By：
 * @version: 1$
 */
public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream inputStream) throws PropertyVetoException, DocumentException {
        // 第一： 使用Dom4j解析配置文件，将解析出来的内容封装到Configration中
        XMLConfigBuilder xmlConfigBuiler = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuiler.parseConfig(inputStream);

        // 第二：创建sqlSessionFactory对象

        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);

        return defaultSqlSessionFactory;

    }
}
